package com.boarsoft.flow.core;

import java.util.Map;

import com.boarsoft.flow.trace.FlowTrace;

/**
 * 
 * 
 * @author Mac_J
 *
 */
public interface SimpleFlow {
	/** 继续执行 */
	public static final short FLAG_GO = 0;
	/** 被挂起 */
	public static final short FLAG_SUSPEND = 1;
	/** 被停止 */
	public static final short FLAG_STOP = 2;
	/** 自主完成停止 */
	public static final short FLAG_END = 3;
	/** 因为超时被中断 */
	public static final short FLAG_TIMEOUT = 4;
	/** 因为异常被中断 */
	public static final short FLAG_ERROR = 5;

	/** 不执行反交易 */
	public static final short REV_TYPE_IGNORE = 0;
	/** 异步执行反交易 */
	public static final short REV_TYPE_ASYNC = 1;
	/** 同步执行反交易（冲正执行完成才让正交易返回） */
	public static final short REV_TYPE_SYNC = 2;
	/** 批量冲正 */
	public static final short REV_TYPE_BATCH = 3;

	/**  */
	public static final short STATUS_NEW = 0;
	/**  */
	public static final short STATUS_EXECUTING = 1;
	/**  */
	public static final short STATUS_SUSPEND = 2;
	/** 主动结束（FLAG_END） */
	public static final short STATUS_SUCCESS = 3;
	public static final short STATUS_FALED = 4;
	public static final short STATUS_TIMEOUT = 5;
	/** 被停止（FLAG_STOP） */
	public static final short STATUS_STOPPED = 6;

	/**  */
	public static final short REV_NONE = 0;
	/**  */
	public static final short REV_EXECUTING = 1;
	/**  */
	public static final short REV_SUCCESS = 2;
	/**  */
	public static final short REV_FAILED = 3;

	/**
	 * 从当前流程对象（模板）复制一份
	 * 
	 * @return
	 */
	SimpleFlow newInstance();

	/**
	 * 是否互斥
	 * 
	 * @return
	 */
	boolean isMutex();

	void setMutex(boolean mutex);

	/**
	 * 流程实例ID
	 * 
	 * @return
	 */
	String getId();

	/**
	 * 流程 bean ID
	 * 
	 * @return
	 */
	String getFlowId();

	/**
	 * 流程入口
	 * 
	 * @return
	 */
	String getEntry();

	void setEntry(String entry);

	void setId(String flowId);

	short getFlag();

	String getStep();

	void setData(Object data);

	void setStep(String step);

	void setFlowId(String flowId);

	void setFlag(short flag);

	Object getData();

	Throwable getError();

	void setError(Throwable throwable);

	long getTimeout();

	void setTimeout(long timeout);

	long getDeadline();

	void setDeadline(long deadline);

	long getStartTime();

	void setStartTime(long startTime);

	/**
	 * 
	 * @return
	 */
	long getEndTime();

	/**
	 * 设置流程的结束时间，并返回流程花费的时间
	 * 
	 * @param endTime
	 * @return
	 */
	void setEndTime(long endTime);

	/**
	 * 返回流程花费的时间<br>
	 * 此方法必须在setEndTime后执行，否则总是返回-1
	 * 
	 * @return 流程花费的时间，如果流程尚未结束，返回-1
	 */
	long getTime();

	String getVer();

	void setVer(String ver);

	boolean getMutex();

	/**
	 * 反交易码
	 * 
	 * @return
	 */
	String getRevCode();

	/**
	 * 反交易码
	 * 
	 * @return
	 */
	void setRevCode(String revCode);

	/**
	 * 反交易执行时机
	 * 
	 * @return
	 */
	short getRevType();

	/**
	 * 反交易执行时机
	 * 
	 * @return
	 */
	void setRevType(short revType);

	/**
	 * 反交易流程入口
	 * 
	 * @return
	 */
	String getRevEntry();

	/**
	 * 反交易流程入口
	 * 
	 * @return
	 */
	void setRevEntry(String revEntry);

	short getStatus();

	void setStatus(short status);

	String getRevFor();

	void setRevFor(String revFor);

	int getRevTime();

	void setRevTime(int revTime);

	int getRevLimit();

	void setRevLimit(int revLimit);

	void setRevStatus(short revStatus);

	short getRevStatus();

	Throwable getRevError();

	void setRevError(Throwable revThrowable);

	void setAddr(String addr);

	String getAddr();

	String getParent();

	void setParent(String parent);

	String getName();

	void setName(String name);

	FlowTrace getTrace();

	boolean isTracing();

	int getTraceRatio();

	String getTraceTarget();

	void setTraceTarget(String traceTarget);

	void setTraceRatio(int traceRatio);

	boolean isTraceIo();

	void setTraceIo(boolean traceIo);

	boolean hasParent();

	Map<String, Object> getAttachments();

	void setAttachments(Map<String, Object> attachments);

}
